package com.cms.customplugin

import com.android.builder.model.SigningConfig
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.TaskAction

class ReinforceTask extends DefaultTask{
    @Internal
    ReinforceBean reinforceBean
    @Internal
    SigningConfig  signingConfig
    @Internal
    File apk

    ReinforceTask(){
        group = "jiagu"
    }


    @TaskAction
    def action(){
        println "apk1111 :${apk} ,apkPath:${apk.absolutePath}"
        //命令行调用-登录
        project.exec {
            it.commandLine("java","-jar",reinforceBean.toolpath,"-login",reinforceBean.username,reinforceBean.password)
        }
        /**导入签名信息
         *java -jar jiagu.jar -importsign <keystore_path> <keystore_password>
         *     <alias> <alias_password>
         注：<keystore_path>请替换为您的密钥文件（扩展名为.jks）的全路径；
         <keystore_password>请替换为您的密钥文件的密码；
         <alias>请替换为您的密钥文件的别名名称；
         <alias_password>请替换为您的密钥文件的别名密码。
         */

        project.exec {
            it.commandLine("java","-jar",reinforceBean.toolpath,"-importsign",signingConfig.getStoreFile().absolutePath,
            signingConfig.storePassword,signingConfig.getKeyAlias(),signingConfig.getKeyPassword())
        }

        project.exec {
            it.commandLine("java","-jar",reinforceBean.toolpath,"-jiagu",apk.absolutePath,apk.parent,"-autosign")
        }

    }
}